package com.hwh.traffic.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import com.hwh.traffic.R;
import com.hwh.traffic.fragment.MainFragment;
import com.hwh.traffic.fragment.MyFragment;
import com.hwh.traffic.fragment.MylikeFragment;
import com.hwh.traffic.fragment.NoticeFragment;
import com.hwh.traffic.utils.ButtonUtil;

/**
 * @author 黄威海
 * @date 2019年12月10日16:56:09
 * @description 主页 Activity
 */
public class MainPageActivity extends AppCompatActivity {

    private ImageView main_page_image;
    private ImageView main_like_image;
    private ImageView main_notice_image;
    private ImageView main_user_image;
    private TextView main_page_text;
    private TextView main_like_text;
    private TextView main_notice_text;
    private TextView main_user_text;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_page);

        MainFragment mainFragment = new MainFragment();
        getSupportFragmentManager().beginTransaction().add(R.id.main_page,mainFragment).commit();

        initNavigationbar();

    }
    public void initNavigationbar(){
        main_page_image = findViewById(R.id.main_page_image);
        main_like_image = findViewById(R.id.main_like_image);
        main_notice_image = findViewById(R.id.main_location_image);
        main_user_image = findViewById(R.id.main_user_image);

        main_page_text = findViewById(R.id.main_page_text);
        main_like_text = findViewById(R.id.main_like_text);
        main_notice_text = findViewById(R.id.main_location_text);
        main_user_text = findViewById(R.id.main_user_text);

        main_page_image.setOnClickListener(v -> {
            if (ButtonUtil.isFastDoubleClick()){
                return;
            }

            main_page_image.setBackgroundResource(R.drawable.mainpage_select);
            main_like_image.setBackgroundResource(R.drawable.like);
            main_notice_image.setBackgroundResource(R.drawable.notice);
            main_user_image.setBackgroundResource(R.drawable.user);

            main_page_text.setTextColor(getResources().getColor(R.color.main_text_select));
            main_like_text.setTextColor(getResources().getColor(R.color.black));
            main_notice_text.setTextColor(getResources().getColor(R.color.black));
            main_user_text.setTextColor(getResources().getColor(R.color.black));

            MainFragment mainFragment = new MainFragment();
            getSupportFragmentManager().beginTransaction().replace(R.id.main_page,mainFragment).commit();

        });

        main_like_image.setOnClickListener(v -> {
            if (ButtonUtil.isFastDoubleClick()){
                return;
            }
            main_like_image.setBackgroundResource(R.drawable.like_select);

            main_page_image.setBackgroundResource(R.drawable.mainpage);
            main_notice_image.setBackgroundResource(R.drawable.notice);
            main_user_image.setBackgroundResource(R.drawable.user);

            main_like_text.setTextColor(getResources().getColor(R.color.main_text_select));
            main_page_text.setTextColor(getResources().getColor(R.color.black));
            main_notice_text.setTextColor(getResources().getColor(R.color.black));
            main_user_text.setTextColor(getResources().getColor(R.color.black));

            MylikeFragment like = new MylikeFragment();
            getSupportFragmentManager().beginTransaction().replace(R.id.main_page,like).commit();

        });

        main_notice_image.setOnClickListener(v -> {

            if (ButtonUtil.isFastDoubleClick()){
                return;
            }
            main_notice_image.setBackgroundResource(R.drawable.notice_select);

            main_page_image.setBackgroundResource(R.drawable.mainpage);
            main_like_image.setBackgroundResource(R.drawable.like);
            main_user_image.setBackgroundResource(R.drawable.user);

            main_notice_text.setTextColor(getResources().getColor(R.color.main_text_select));
            main_like_text.setTextColor(getResources().getColor(R.color.black));
            main_page_text.setTextColor(getResources().getColor(R.color.black));
            main_user_text.setTextColor(getResources().getColor(R.color.black));

            NoticeFragment noticeFragment = new NoticeFragment();
            getSupportFragmentManager().beginTransaction().replace(R.id.main_page,noticeFragment).commit();

        });

        main_user_image.setOnClickListener(v -> {

            if (ButtonUtil.isFastDoubleClick()){
                return;
            }
            main_user_image.setBackgroundResource(R.drawable.user_select);

            main_page_image.setBackgroundResource(R.drawable.mainpage);
            main_like_image.setBackgroundResource(R.drawable.like);
            main_notice_image.setBackgroundResource(R.drawable.notice);

            main_user_text.setTextColor(getResources().getColor(R.color.main_text_select));
            main_like_text.setTextColor(getResources().getColor(R.color.black));
            main_notice_text.setTextColor(getResources().getColor(R.color.black));
            main_page_text.setTextColor(getResources().getColor(R.color.black));

            MyFragment myFragment = new MyFragment();
            getSupportFragmentManager().beginTransaction().replace(R.id.main_page,myFragment).commit();

        });

    }


}